package blog.com.mw.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import blog.com.mw.base.ResultData;
import blog.com.mw.pojo.vo.DiscussVO;
import blog.com.mw.service.DiscussService;

@RestController
@RequestMapping("/discuss")
public class DiscussController {

	@Autowired
	private DiscussService service;
	
	@RequestMapping(value = "/discuss", method = RequestMethod.GET)
	public ResultData getDiscussById(@RequestParam("id") int id) {
		ResultData rs = null;
		rs = service.getDiscussById(id);
		return rs;
	}
	@RequestMapping(value = "/discussList", method = RequestMethod.GET)
	public ResultData getAllDiscuss(@RequestParam("page") int pageNum,@RequestParam("limit") int pageSize
			,@RequestParam(value="keyword", required=false)String keyword) {
		ResultData rs = null;
		rs = service.getAllDiscuss(pageNum,pageSize,keyword);
		return rs;
	}
	
	@RequestMapping(value = "/getDiscussByArticleId",method = RequestMethod.GET)
	public ResultData getDiscussByArticleId(@RequestParam("articleId") int articleId) {
		ResultData rs = null;
		rs = service.getDiscussByArticleId(articleId);
		return rs;
	}
	
	@RequestMapping(value = "/getDiscussByUserId",method = RequestMethod.GET)
	public ResultData getDiscussByUserId(@RequestParam("userId") int userId) {
		ResultData rs = null;
		rs = service.getDiscussByUserId(userId);
		return rs;
	}
	
	@RequestMapping(value = "/discuss", method = RequestMethod.POST)
	public ResultData addDiscuss(@RequestBody DiscussVO vo) {
		ResultData rs = null;
		rs = service.addDiscuss(vo);
		return rs;
	}
	
	@RequestMapping(value = "/discuss", method = RequestMethod.PUT)
	public ResultData updateDiscuss(@RequestBody DiscussVO vo) {
		ResultData rs = null;
		rs = service.updateDiscuss(vo);
		return rs;
	}
	
	@RequestMapping(value = "/discuss/{id}", method = RequestMethod.DELETE)
	public ResultData delDiscuss(@PathVariable("id") int id) {
		ResultData rs = null;
		List<Integer> ids = new ArrayList<>();
		ids.add(id);
		rs = service.delDiscuss(ids);
		return rs;
	}
	
	@RequestMapping(value = "/discuss", method = RequestMethod.DELETE)
	public ResultData delDiscuss(@RequestBody List<Integer> ids) {
		ResultData rs = null;
		rs = service.delDiscuss(ids);
		return rs;
	}
}
